﻿using System;
using System.Web.UI.WebControls;
using Bingosoft.Modules.SecurityConsole.Organization;
using Bingosoft.Web.Utils;

namespace Bingosoft.WebApp.Modules.SecurityConsole.Organization
{
    public partial class OrganizationManageRoleList : System.Web.UI.BasePage
    {
        private OrganizationService _service;
        private OrganizationService Service
        {
            get
            {
                return _service ?? (_service = ObjectHelper.GetObject<OrganizationService>());
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void SearchGrid(object sender, EventArgs e)
        {
            Refresh();
        }

        protected void RemoveRolesFromUser(object sender, EventArgs e)
        {
            string orgId = Request.QueryString["OrgId"];
            string[] roleIds = SmartGridView1.GetCheckedValues();
            Service.RemoveManageRolesForOrganization(orgId, roleIds);
            Refresh();
        }

        protected void RemoveRoleFromUser(object sender, EventArgs e)
        {
            ImageButton img = sender as ImageButton;
            string roleId = img.Attributes["_KeyId"];
            string orgId = Request.QueryString["OrgId"];
            Service.RemoveManageRoleForOrganization(orgId, roleId);
            Refresh();
        }

        private void Refresh()
        {
            this.SmartGridView1.DataBind();
        }
    }
}